import Vue from 'vue'
import router from './router'
import axios from 'axios'
// import env from './env'
import vueLazyLoad from 'vue-lazyload'
import VueCookie from 'vue-cookie'
//引入element ui
import {
  Message
} from 'element-ui'
import store from './store'
import App from './App.vue'

//启用mock拦截,mock开关
// const mock = true;
// if(mock){
//   require('./mock/api');
// }
//设置默认URL
axios.defaults.baseURL = '/api';
//设置超时时间
axios.defaults.timeout = 5000;
//根据环境变量获取不同的请求地址
// axios.defaults.baseURL = env.baseURL;
//拦截器
axios.interceptors.response.use(function (response) {
  let res = response.data;
  let path = location.hash;
  if (res.status == 0) {
    return res.data;
    //当状态码为10时，错误拦截
  } else if (res.status == 10) {
    if (path != '#/index') {
      window.location.href = '/#/login';
    }
    return Promise.reject(res);
  } else {
    Message.warning(res.msg);
    return Promise.reject(res);
  }
}, (err) => {
  let res = err.response;
  Message.error(res.data.message);
  return Promise.reject(err);
});

Vue.prototype.$message = Message;
Vue.prototype.axios = axios;
Vue.use(vueLazyLoad, {
  loading: '/imgs/loading-svg/loading-bars.svg',
});
Vue.use(VueCookie);
Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')